package cn.dengta.webapp.trade.dto;

import java.util.Map;

import cn.dengta.context.rpc.CachedConfig;
import cn.dengta.context.rpc.CachedConfigManager;
import lombok.Getter;
import lombok.Setter;

/**
 * 充值录音审核
 *
 * @author lizhichao
 * @since 2024-04-01
 */
@Setter
@Getter
public class PayRiskRecordConfig {

	/** 充值提醒总开关 */
	Boolean enable;
	/** 触发金额 */
	Integer triggerAmount;
	/** 触发周期，天 */
	Integer triggerCycle;
	/** 待审核中，允许充值金额 */
	Integer waitAmount;
	/** 待审核中，允许充值次数 */
	Integer waitNum;
	/** 弹窗内容 */
	String popupContent;
	/** 弹窗内容宽 */
	Integer popupWide;
	/** 弹窗内容高 */
	Integer popupHigh;
	/** 拒绝后，允许重试次数 */
	Integer rejectNum;
	/** 公众号开关 */
	Map<Long, Boolean> officialAccounts;

	private static final class InstanceHolder {

		static final CachedConfig<PayRiskRecordConfig> INSTANCE = CachedConfigManager.create("pay_risk_record_config", PayRiskRecordConfig.class, PayRiskRecordConfig::getDefault);

	}

	public static PayRiskRecordConfig getCache() {
		return InstanceHolder.INSTANCE.get();
	}

	public static void setCache(PayRiskRecordConfig config) {
		InstanceHolder.INSTANCE.set(config);
	}

	public boolean officialAccountsEnable(Long oaId) {
		if (oaId == null || officialAccounts == null) {
			return false;
		}
		return officialAccounts.getOrDefault(oaId, false);
	}

	public Integer getRejectNum() {
		return rejectNum == null ? 0 : rejectNum;
	}

	private static PayRiskRecordConfig getDefault() {
		PayRiskRecordConfig cfg = new PayRiskRecordConfig();
		cfg.setEnable(false);
		cfg.setPopupContent("");
		cfg.setPopupWide(0);
		cfg.setPopupHigh(0);
		cfg.setPopupContent("");
		cfg.setTriggerAmount(1500);
		cfg.setTriggerCycle(15);
		cfg.setWaitNum(2);
		cfg.setWaitAmount(3000);
		cfg.setRejectNum(0);
		return cfg;
	}

}
